Electrical Engineering (EE) Exam  >  Electrical Engineering (EE) Questions  >  What will be the output of the following code... Start Learning for Free
What will be the output of the following code snippet?
#include <stdio.h>
void solve() {
    bool ok = false;
    printf(ok ? "YES" : "NO");
}
int main() {
    solve();
    return 0;
}
  • a)
    Yes
  • b)
    No
  • c)
    Compilation Error
  • d)
    None of the above
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
What will be the output of the following code snippet?#include <std...
The code snippet will result in undefined behavior because the variable ok is uninitialized. In C, variables that are not explicitly initialized can have unpredictable values.
The printf statement uses the ternary operator (ok ? "YES" : "NO") to determine the string to be printed based on the value of ok. However, since ok is uninitialized, its value is indeterminate.
Therefore, the output of the printf statement cannot be determined reliably. It could print "YES" or "NO" or any other unexpected result depending on the uninitialized value of ok.
As a result, the correct answer is C. None of the above.
View all questions of this test
Most Upvoted Answer
What will be the output of the following code snippet?#include <std...
The code snippet will result in undefined behavior because the variable ok is uninitialized. In C, variables that are not explicitly initialized can have unpredictable values.
The printf statement uses the ternary operator (ok ? "YES" : "NO") to determine the string to be printed based on the value of ok. However, since ok is uninitialized, its value is indeterminate.
Therefore, the output of the printf statement cannot be determined reliably. It could print "YES" or "NO" or any other unexpected result depending on the uninitialized value of ok.
As a result, the correct answer is C. None of the above.
Free Test
Community Answer
What will be the output of the following code snippet?#include <std...
Explanation:

Compilation Error:
- The code snippet will throw a compilation error because the data type `bool` is not recognized in standard C.
- The `bool` data type is introduced in C++ (C++98) and C99, but not in standard C (C89).
Therefore, the correct answer is option 'C' - Compilation Error.
Explore Courses for Electrical Engineering (EE) exam
Question Description
What will be the output of the following code snippet?#include <stdio.h>void solve() { bool ok = false; printf(ok ? "YES" : "NO");}int main() { solve(); return 0;}a)Yesb)Noc)Compilation Errord)None of the aboveCorrect answer is option 'C'. Can you explain this answer? for Electrical Engineering (EE) 2025 is part of Electrical Engineering (EE) preparation. The Question and answers have been prepared according to the Electrical Engineering (EE) exam syllabus. Information about What will be the output of the following code snippet?#include <stdio.h>void solve() { bool ok = false; printf(ok ? "YES" : "NO");}int main() { solve(); return 0;}a)Yesb)Noc)Compilation Errord)None of the aboveCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Electrical Engineering (EE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What will be the output of the following code snippet?#include <stdio.h>void solve() { bool ok = false; printf(ok ? "YES" : "NO");}int main() { solve(); return 0;}a)Yesb)Noc)Compilation Errord)None of the aboveCorrect answer is option 'C'. Can you explain this answer?.
Solutions for What will be the output of the following code snippet?#include <stdio.h>void solve() { bool ok = false; printf(ok ? "YES" : "NO");}int main() { solve(); return 0;}a)Yesb)Noc)Compilation Errord)None of the aboveCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Electrical Engineering (EE). Download more important topics, notes, lectures and mock test series for Electrical Engineering (EE) Exam by signing up for free.
Here you can find the meaning of What will be the output of the following code snippet?#include <stdio.h>void solve() { bool ok = false; printf(ok ? "YES" : "NO");}int main() { solve(); return 0;}a)Yesb)Noc)Compilation Errord)None of the aboveCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What will be the output of the following code snippet?#include <stdio.h>void solve() { bool ok = false; printf(ok ? "YES" : "NO");}int main() { solve(); return 0;}a)Yesb)Noc)Compilation Errord)None of the aboveCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for What will be the output of the following code snippet?#include <stdio.h>void solve() { bool ok = false; printf(ok ? "YES" : "NO");}int main() { solve(); return 0;}a)Yesb)Noc)Compilation Errord)None of the aboveCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of What will be the output of the following code snippet?#include <stdio.h>void solve() { bool ok = false; printf(ok ? "YES" : "NO");}int main() { solve(); return 0;}a)Yesb)Noc)Compilation Errord)None of the aboveCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What will be the output of the following code snippet?#include <stdio.h>void solve() { bool ok = false; printf(ok ? "YES" : "NO");}int main() { solve(); return 0;}a)Yesb)Noc)Compilation Errord)None of the aboveCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Electrical Engineering (EE) tests.
Explore Courses for Electrical Engineering (EE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev